package com.wmh.baseservice.operationaid.controller;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wmh.baseservice.common.utils.returnbody.ReturnBody;
import com.wmh.baseservice.operationaid.entity.KeyWordBrandCharacter;
import com.wmh.baseservice.operationaid.service.KeyWordBrandCharacterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.util.List;

import static com.wmh.baseservice.common.utils.returnbody.ReturnBody.success;

/**
 * @author dongaolong
 * @createDate 2023-07-06
 */
@Validated
@RestController
@RequestMapping("operationAid/KeyWordBrandCharacter")
@Api(tags = "关键字品牌字符管理")
@Slf4j
public class KeyWordBrandCharacterController {

    @Resource
    private KeyWordBrandCharacterService keyWordBrandCharacterService;

    @ApiOperation("添加")
    @PostMapping("/commit")
    public String commit(@NotBlank(message = "请提交名称") String name){
        keyWordBrandCharacterService.commitBrandCharacter(name);
        return ReturnBody.success();
    }

    @ApiModelProperty(value = "删除")
    @PostMapping("/delete")
    public String delete(
            @NotBlank(message = "未提交主键")
            @Size(min = 3, message = "未提交主键")
            String ids) {
        keyWordBrandCharacterService.delete(JSON.parseArray(ids,Long.class));
        return success();
    }

    @ApiOperation("获取关键词作用记录列表")
    @PostMapping("/list")
    public String list() {
        List<KeyWordBrandCharacter> list = keyWordBrandCharacterService.list(new QueryWrapper<KeyWordBrandCharacter>()
                .select(KeyWordBrandCharacter.ID, KeyWordBrandCharacter.NAME)
                .orderByDesc(KeyWordBrandCharacter.CREATE_TIME));
        return success(list);
    }
}
